//
//  Info2CollectionViewCell.m
//  markmap
//
//  Created by 甘世清 on 2024/4/24.
//

#import "Info2CollectionViewCell.h"

@implementation Info2CollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    self.contentView.layer.cornerRadius = 10;
    self.contentView.clipsToBounds = YES;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.layer.borderWidth = 1;
    self.contentView.layer.borderColor = UIColor.whiteColor.CGColor;
    [self.contentView addSubview:self.topImage];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.timeLabel];
    [self.topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(30);
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(20);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(60);
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(90);
    }];
}
- (void)setModel:(InfoModel *)model{
    _model = model;
    self.nameLabel.text = model.name;
    self.timeLabel.text = model.time;
    if (model.isSeleted) {
        self.topImage.image =  SQGetImage(model.name);
        self.nameLabel.textColor = UIColor.whiteColor;
        self.timeLabel.textColor = UIColor.whiteColor;
        self.contentView.layer.borderColor = UIColor.whiteColor.CGColor;
    } else {
        NSString * name = [NSString stringWithFormat:@"%@-2",model.name];
        self.topImage.image = SQGetImage(name);
        self.nameLabel.textColor = SQColor999999;
        self.timeLabel.textColor = SQColor999999;
        self.contentView.layer.borderColor = SQColor999999.CGColor;
    }
}
- (UIImageView *)topImage{
    if (!_topImage) {
        _topImage = [[UIImageView alloc]init];
        _topImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _topImage;
}
- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT_MEDIUM(16);
        _nameLabel.textColor = UIColor.whiteColor;
    }
    return _nameLabel;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = FONT_REGULAR(12);
        _timeLabel.textColor = UIColor.whiteColor;
    }
    return _timeLabel;
}

@end
